<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="mac5855.app.dao.CategoriaDAO"%>
<%@page import="mac5855.app.models.Categoria"%>
<%@page import="mac5855.app.dao.DAOFactory"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="mac5855.app.dao.DenunciaDAO"%>
<%@page import="mac5855.app.models.Denuncia"%>
<%@page import="mac5855.app.dao.DAOFactory"%>
<%@page import="mac5855.app.dao.PerguntaDAO"%>
<%@page import="mac5855.app.models.Pergunta"%>
<%@page import="mac5855.app.dao.UsuarioDAO"%>
<%@page import="mac5855.app.models.Usuario"%><html xmlns="http://www.w3.org/1999/xhtml">




<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link href="/sistemaperguntaresposta/css/style.css" media="all" type="text/css" rel="stylesheet" />
</head>

<body>

<div id="centralizer">
	<jsp:include page="/header.jsp"></jsp:include>
    <h1>Cadastro de Usuários</h1>

    <div id="home" class="content">
    	<div class="question_box">
    		<form action="/sistemaperguntaresposta/controller?business=UsuarioController" method="post">
	<p>
		<label for="nome">Nome:</label>
		<input type="text" name="nome"/>
	</p>
	<p>
		<label for="email">Email:</label>
		<input type="text" name="email"/>
	</p>
	<p>
		<label for="senha">Senha:</label>
		<input type="password" name="senha"/>
	</p>
	<p>
		<label for="confirme_senha">Confirme Senha:</label>
		<input type="password" name="confirme_senha"/>
	</p>
	<p>
	<label for="tipo">Tipo de Usuário:</label>
	<select name="tipo">
		<option value="admin">Admin</option>
		<option value="normal">Normal</option>
	</select>
	</p>
	<p>
		<input type="submit" value="Enviar"/>
	</p>
</form>
        </div>
        
        <div class="separator"></div>
        
        <div class="category_box">
        	<h3>Acoes</h3>
            <div class="dashed_separator"></div>
        	<ul>
                <li><a href="/sistemaperguntaresposta/admin/">Administracao de Usuários</a></li>
                <li><a href="/sistemaperguntaresposta/admin/busca.jsp">Perguntas</a></li>
            </ul>
        </div>
        
        <div class="search_box">
        	<form action="/sistemaperguntaresposta/controller?business=UsuarioController" method="post">
	        	<h3>Buscar Usuário</h3>
	            <div class="dashed_separator"></div>
	            <input type="hidden" name="action" value="search"/>
	           	<input type="text" class="input_text" name="search"/>
	           	<select name="tipo">
	           		<option value="">Todos</option>
					<option value="admin">Admin</option>
					<option value="normal">Normal</option>
				</select>
	           	<input type="submit" class="input_button" value="Buscar" />
           	</form>
        </div>
        
        <div class="question_list_box">
            <h3>Usuários</h3>
            <div class="dashed_separator"></div>
        	<ul>
        	
        		<% 	
        		Usuario[] usuarios = {};
        		if(request.getParameter("search") == null) {
	        		UsuarioDAO usuariodao = DAOFactory.getDAOFactory(DAOFactory.JDBC).getUsuarioDAO();
					usuarios = usuariodao.findAll();
        		}
        		else {
        			String search = (String) request.getParameter("search");
        			String tipo = (String) request.getParameter("tipo");
        			UsuarioDAO usuariodao = DAOFactory.getDAOFactory(DAOFactory.JDBC).getUsuarioDAO();
					usuarios = usuariodao.findAllByEmailOrNomeAndTipo(search,tipo);
        		}
	int i = 0;
	for (Usuario usuario : usuarios ) {
		String liClass = ((i % 2) == 0) ? "colored" : "";
		i++;

%>

	<li class="<%= liClass %>"><div><%= usuario.getTipo() %> - <%= usuario.getEmail() %><a href="/sistemaperguntaresposta/controller?business=UsuarioController&action=delete&id=<%= usuario.getEmail() %>">Remover</a></div><%= usuario.getNome()%><div class="cleaner"></div></li>

<% } %>
        	
        		
                
            </ul>
        </div>
        
        <div class="cleaner"></div>
    </div>
    
    <div class="footer">
    </div>
</div>

</body>
</html>


